package com.example.eback.util;
import com.example.eback.dao.UserDAO;
import com.example.eback.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserUtils {
    @Autowired
    UserDAO userDAO;
    // 获取当前认证的用户信息
    public User getCurrentUser() {
        Subject subject = SecurityUtils.getSubject();
        if(subject!=null){
            Object object= subject.getPrincipal();
            if(object!=null){
                String username= subject.getPrincipal().toString();
                User currenUser=userDAO.findByUsername(username);
                return currenUser;
            }
        }
        return null;
    }
}
